//
//  DetailsViewController.m
//  Ai
//
//  Created by 杜超男 on 2019/3/6.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "DetailsViewController.h"
#import "DetailsTableViewCell.h"
#import "Masonry.h"
@interface DetailsViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong)UITableView *tableView;
@property (nonatomic , strong)NSArray *nameArr;
@property (nonatomic , strong)NSArray *byArr;
@property (nonatomic , strong)NSArray *moneyArr;

@end

@implementation DetailsViewController
-(NSArray *)nameArr{
    _nameArr = [[NSArray alloc] initWithObjects:@"李建" , @"刘依依" , @"易烊千玺" ,  @"易烊千玺" , @"王俊凯",nil];
    return _nameArr;
}
-(NSArray *)byArr{
    _byArr = [[NSArray alloc] initWithObjects:@"VIP" , @"VIP" , @"VIP" , @"VIP" , @"普通", nil];
    return _byArr;
}
-(NSArray *)moneyArr{
    _moneyArr = [[NSArray alloc] initWithObjects:@"$199" , @"$199" , @"$199" ,  @"$199" , @"$199",nil];
    return _moneyArr;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //rgba(230/255.0, 230/255.0, 230/255.0, 1)
    UIView *HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
    HeaderView.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    //学生姓名
    UILabel *StudentsName = [[UILabel alloc] initWithFrame:CGRectMake(40,16,80,13)];
    StudentsName.text = @"学生姓名";
    StudentsName.font = [UIFont systemFontOfSize:14];
    [HeaderView addSubview:StudentsName];
    //用户类型
    UILabel *UserType = [[UILabel alloc] initWithFrame:CGRectMake(150,16,80,13)];
    UserType.text = @"用户类型";
    UserType.font = [UIFont systemFontOfSize:14];
    [HeaderView addSubview:UserType];
    //购买服务类型
    UILabel *ByServeType = [[UILabel alloc] initWithFrame:CGRectMake(260,16,100,13)];
    ByServeType.text = @"购买服务类型";
    ByServeType.font = [UIFont systemFontOfSize:14];
    [HeaderView addSubview:ByServeType];
    return HeaderView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(leftBtn)];
    // Do any additional setup after loading the view from its nib.
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(15, 204, self.view.frame.size.width - 15, self.view.frame.size.height - 104) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;[_tableView registerNib:[UINib nibWithNibName:@"DetailsTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tableView];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(100);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom).inset(0);
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[DetailsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    //防止cell复用带来的控件重叠
//    for (UIView *view in cell.contentView.subviews) {
//        [view removeFromSuperview];
//    }
    cell.StudentName.text = self.nameArr[indexPath.row];
    cell.ByByBy.text = self.byArr[indexPath.row];
    cell.Money.text = self.moneyArr[indexPath.row];
    
    //rgba(247/255.0, 247/255.0, 247/255.0, 1)
    cell.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1];
    return cell;
}
- (void)leftBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
   self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    //    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    //    [self.navigationController.navigationBar setShadowImage:nil];
}

@end
